import { Entity, model, property, hasMany, belongsTo } from '@loopback/repository';
import { Todo } from './todo.model';
import { User } from './user.model';

@model()
export class TodoList extends Entity {
  @property({
    type: 'number',
    id: true,
  })
  id?: number;

  @property({
    type: 'string',
    required: true,
  })
  title: string;

  @hasMany(() => Todo)
  // @property.array(() => Todo)
  todos?: Todo[];

  @belongsTo(() => User)
  userId: number;

  @property({
    type: 'date',
    // required: true,
    default: new Date()
  })
  created: Date;

  @property({
    type: 'date',
    // required: true,
    default: new Date()
  })
  lastUpdated: Date;

  constructor(data?: Partial<TodoList>) {
    super(data);
  }
}
